/^[a-z0-9][a-z0-9_]{2,28}[a-z0-9]$/i
^(?=\P{Ll}*\p{Ll})(?=\P{Lu}*\p{Lu})(?=\P{N}*\p{N})(?=[\p{L}\p{N}]*[^\p{L}\p{N}])[\s\S]{8,}$
if (preg_match('/^[A-Za-z]{1}[A-Za-z0-9]{5,31}$/', "moo123")) { echo 'succeeded'; } else { echo 'failed'; }